Skip to content

Stop ignoring mistyped transition thresholds - #836

Merged
hollomancer merged 2 commits into
mainfrom
claude/nifty-sagan-y8fcgd-env-parse
Nov 21, 2026
Merged

hollomancer merged 2 commits into
mainfrom
claude/nifty-sagan-y8fcgd-env-parse

Conversation

@hollomancer

Copy link
Copy Markdown
Owner

Description

Problem. The transition assets read their quality-gate thresholds through _env_float and _env_int in packages/sbir-analytics/sbir_analytics/assets/transition/utils.py. Both helpers caught every exception and returned the default. If an operator set SBIR_ETL__TRANSITION__CONTRACTS__DATE_COVERAGE_MIN=0,8 or abc, the run quietly used 0.90 and left no trace.

Change.

  • Added env_float(key, default) and env_int(key, default) to sbir_etl/config/loader.py. sbir_etl/config/ had no numeric env reader before this, so these are new. (The existing _convert_env_value guesses a type for generic overrides and falls back to a string. It does not do this job.)
    • An unset, empty, or whitespace-only variable returns the default.
    • Surrounding whitespace is stripped (" 0.8 " gives 0.8).
    • A set value that does not parse raises ValueError naming the variable and the value, for example Environment variable SBIR_ETL__...=' 0,8' is not a valid number.
    • env_float also rejects nan and inf. Every threshold comparison against a non-finite value fails, or every one passes, so a non-finite threshold is never what the operator meant.
    • env_int rejects "5.0" and "1e3". It does not round.
  • transition/utils.py now re-exports these as _env_float / _env_int. The two copies that swallowed errors are deleted.

Call sites touched. All 28 _env_float / _env_int calls in transition/ (analytics, checks, contracts, detections, evidence, scoring, vendor_resolution). None of them changed. They now pick up the strict behavior through the re-export. (The commit message says 19. The correct count is 28.)

What was not changed.

  • I searched packages/ and sbir_etl/ for env reads wrapped in try/except. I found no other numeric parser that swallows errors.
  • uspto/utils.py (TRANSFORM_SUCCESS_THRESHOLD, LINKAGE_TARGET) and cet/validation.py call float(os.environ.get(...)) directly. A bad value there already raises, although the message does not name the variable. uspto/ai_extraction.py reads only paths and table names.
  • _env_bool still treats any value it does not recognize as false. This PR covers numeric parsing only.
  • phase_transition/utils.parse_data_cut_date logs a warning on a bad date and falls back to today. This is a date read, not a numeric one, so I left it out of scope. It may deserve its own fix.
  • Routing all SBIR_ETL__* reads through the loader is not part of this PR.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

A run that used to continue with a mistyped threshold will now stop with an error. That is the intended fix.

Versioning Impact

  • PATCH: backward-compatible fix or documentation correction

Testing

  • tests/unit/config/test_env_numbers.py (31 cases): unset and empty/blank values return the default; valid int and float values parse, with whitespace; these must fail: abc, 0,8, 1e, nan, NaN, inf, -inf, 80% for float, and abc, 0,8, 1e, 5.0, 1e3, 10,000 for int.

  • tests/unit/assets/test_transition_env_thresholds.py: calls the real contracts_sample_quality_check. A bad DATE_COVERAGE_MIN (0,8, abc) or SAMPLE_SIZE_MIN (1e3) must raise. A valid " 0.5 " must show up in the check metadata.

  • On main: the 3 bad-value asset-check tests fail with DID NOT RAISE. The helper tests fail at import because the helper did not exist yet.

  • Passed locally: ruff check and ruff format --check on the changed files, uv run mypy sbir_etl, make lint-boundaries, Definitions.validate_loadable(defs), and pytest -n auto -m "not slow" tests/unit (7102 passed, 7 skipped).

  • Unit tests added/updated

  • All tests pass locally


Generated by Claude Code

The transition assets read quality-gate thresholds with _env_float and
_env_int. Both caught every parse error and returned the default, so a
value such as "0,8" or "abc" was dropped without a trace and the run used
a different threshold than the operator set.

Add env_float and env_int to sbir_etl/config/loader.py. An unset, empty,
or blank variable still returns the default. A set value that does not
parse raises ValueError naming the variable and the value. env_float also
rejects nan and inf, because a non-finite threshold makes every
comparison pass or fail. The transition utils now re-export these readers
under their old names, so the 19 call sites keep working unchanged.

Tests cover the helpers and one real asset check
(contracts_sample_quality_check). The three bad-value check tests fail
on main with "DID NOT RAISE".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012JfLFUjobV2gCR9fEoypYT
Copilot AI balanced review requested due to automatic review settings November 21, 2026 19:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

transformed_transition_evidence read the contracts-sample and
vendor-resolution thresholds inside best-effort try/except blocks. A bad
value such as "0,8" raised ValueError, the block swallowed it, and the
gate entry vanished from reports/validation/transition_mvp.json. The
reads now happen before those blocks, so a bad value stops the asset.
The blocks still guard reading the optional checks JSON files.

scripts/ci/gate_check.py kept its own _env_float that returned the
default on any parse error. It now uses sbir_etl.config.loader.env_float,
so MIN_AWARD_RATE and MIN_COMPANY_RATE fail the same way. ruff format
also reflowed one print call in that file.

New tests: the evidence asset and the analytics gate raise on "0,8"-style
values. All three fail on the previous commit with "DID NOT RAISE".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012JfLFUjobV2gCR9fEoypYT
@hollomancer
hollomancer merged commit 708f3d4 into main Nov 21, 2026
19 checks passed
@hollomancer
hollomancer deleted the claude/nifty-sagan-y8fcgd-env-parse branch November 21, 2026 21:02
hollomancer pushed a commit that referenced this pull request Nov 21, 2026
Resolve the conflict in assets/transition/utils.py: #836 replaced the local
error-swallowing _env_float/_env_int with imports from sbir_etl.config.loader,
and this branch removed the _norm_name wrapper. Keep neither local block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012JfLFUjobV2gCR9fEoypYT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants